package cn.tedu.sp09.controller;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp09.service.ItemFeignService;
import cn.tedu.sp09.service.OrderFeignService;
import cn.tedu.sp09.service.UserFeignService;
import cn.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class FeignController {
    @Autowired
    private ItemFeignService itemFeignService;
    @Autowired
    private UserFeignService userFeignService;
    @Autowired
    private OrderFeignService orderFeignService;
    @GetMapping("/item-service/{orderId}")
    JsonResult<List<Item>> getItems(@PathVariable String orderId){
        //调用远程商品服务
       return itemFeignService.getItems(orderId);
    }
    @PostMapping("/item-service/decreaseNumber")
    JsonResult<?> decreaseNumber(@RequestBody List<Item> items){
        return itemFeignService.decreaseNumber(items);
    }
    @GetMapping("/user-service/{userId}")
    JsonResult<User> getUser(@PathVariable Integer userId){
        return userFeignService.getUser(userId);
    }
    @GetMapping("/user-service/{userId}/score")
    JsonResult<?> addScore(@PathVariable Integer userId,@RequestParam Integer score){
        return userFeignService.addScore(userId, score);
    }
    @GetMapping("/order-service/{orderId}")
    JsonResult<Order> getOrder(@PathVariable String orderId){
        return orderFeignService.getOrder(orderId);
    }
    @GetMapping("/order-service")
    JsonResult<?> addOrder(){
        return orderFeignService.addOrder();
    }
}
